//
//  CYCallRecord.m
//  CreditAddressBook
//
//  Created by Lee on 15/6/8.
//  Copyright (c) 2015年 Lee. All rights reserved.
//

#import "CYCallRecord.h"
#import "CYCreditTool.h"
#import "CYDialTool.h"
#import "CYPerson.h"

@implementation CYCallRecord

+ (instancetype)callRecord {
    return [[self alloc] init];
}

- (void)setIndexPath:(NSIndexPath *)indexPath {
    _indexPath = indexPath;
}

- (NSString *)newlyCallDate {
    if (_newlyCallDate) {
        return _newlyCallDate;
    }
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:self.callHistory.createTime];
    NSString *dateStr = [CYCreditTool timeWithDate:date formatter:CYTimeFormatHmType];
    return dateStr;
}

- (NSString *)newlyCallDate1 {
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:self.callHistory.createTime];
    NSString *dateStr = [CYCreditTool timeWithDate:date formatter:CYTimeFormatYMDHmsType];
    return dateStr;
}

- (NSString *)callDuration {
    if (self.callHistory.duration) {
        
        NSString *callTime = [CYDialTool callTime:self.callHistory.duration];
      
        return callTime;
        
    }
    return @"0时0分0秒";
}

- (NSString *)callDurationSum {
    if (self.callHistory.durationSum) {
        NSString *callDurationSumTime = [CYDialTool callTime:self.callHistory.durationSum];
        return callDurationSumTime;
    }
    return @"0时0分0秒";
}



- (NSString *)callDurationSum1 {
    if (self.callHistory.durationSum) {
        NSString *callDurationSumTime = [CYDialTool callTime1:self.callHistory.durationSum];
        return callDurationSumTime;
    }
    return @"00:00";
}

- (NSString *)times {
    return [NSString stringWithFormat:@"%ld", (long)self.callHistory.num];
}

- (NSString *)callName {
    if (self.callHistory.name && ![self.callHistory.name isEqualToString:@""]) {
        return self.callHistory.name;
    }
    return self.callHistory.phone;
}

- (UIImage *)thumbnailLocal {
    if (self.callHistory.thumbnail) {
        return self.callHistory.thumbnail;
    } else if (self.person.person.thumbnail) {
        return self.person.person.thumbnail;
    }
    return nil;
}
@end
